﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EasyStep.Attributes
{
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
    public class TestAction: Attribute
    {
        public Guid Id { get; set; }
        public Guid ParentId { get; set; }
        public Type ParentType { get; set; }
        public Type CurrentType { get; set; }

        public bool RequireLocator { get; set; }
        public bool RequireData { get; set; }
        public bool RequireScreenShot { get; set; }
        public bool IsAbstract { get; set; }
        
        public string Name{get; set;}
        public string Description{get; set;}
        public int OrderNumber { get; set; }
        public TestAction Parent { get;set; }

        public TestAction():this(null,string.Empty,true, true,false){}
        public TestAction(Type parent) : this(parent, string.Empty, true, true, false) { }
        public TestAction(Type parent, string name) : this(parent, name, true, true, false) { }
        /// <summary>
        /// Attribute with specific name, and parent type
        /// </summary>        
        /// <param name="parent">parent action, which is parent for current action</param>
        /// <param name="name">unique child name of that attribute, could be empty -then data will come from type name</param>
        public TestAction(Type parent, string name, bool requireLocator, bool requireData, bool requireScreenShot)
        {
            this.ParentType = parent;
            this.Name = name;
            this.ParentId = this.ParentType == null ? Guid.Empty : this.ParentType.GUID;
            RequireLocator = requireLocator;
            RequireData = requireData;
            RequireScreenShot = requireScreenShot;
            IsAbstract = false;
        }

        /// <summary>
        /// Needs to initialize Action Id, Name, Type to execute 
        /// </summary>
        /// <param name="t">all information is coming from type which this attribute has been applied</param>
        /// <returns>initialized action instance</returns>
        public TestAction Init(Type t)
        {
            this.CurrentType = t;
            this.Id = t.GUID;
            this.Name = !string.IsNullOrEmpty(this.Name)?this.Name: t.Name;
            return this;
        }

        
    }
}